package cn.fulong.sso.client.utils;



import java.util.Date;
import java.util.HashMap;
import java.util.Map;


/**
 * @Version 1.0
 * @Author: 云树
 * @Description:
 * @Date: 2019/3/12
 * @Modify 云树
 * @ModifyDate 2019/3/12
 * @since 1.0
 */
public class SSOHashMap extends HashMap<String, String> {
    private static final long serialVersionUID = -1277791390391391631L;

    public SSOHashMap() {
    }

    public SSOHashMap(Map<? extends String, ? extends String> m) {
        super(m);
    }

    public String put(String key, Object value) {
        String strValue;
        if (value == null) {
            strValue = null;
        } else if (value instanceof String) {
            strValue = (String) value;
        } else if (value instanceof Integer) {
            strValue = ((Integer) value).toString();
        } else if (value instanceof Long) {
            strValue = ((Long) value).toString();
        } else if (value instanceof Float) {
            strValue = ((Float) value).toString();
        } else if (value instanceof Double) {
            strValue = ((Double) value).toString();
        } else if (value instanceof Boolean) {
            strValue = ((Boolean) value).toString();
        } else if (value instanceof Date) {
            strValue = ((Long)((Date) value).getTime()).toString();
        } else {
            strValue = value.toString();
        }

        return this.put(key, strValue);
    }

    public String put(String key, String value) {
        return StringSelfUtil.areNotEmpty(key, value) ? (String) super.put(key, value) : null;
    }
}
